<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('WorkDay/item_save')}" method="post">
        <table>
            <tr class="checkboxs">
                <th>工作日设置：</th><td>
                    <script type="text/javascript">
                        var days = ['一', '二', '三', '四', '五', '六', '日'];
                        var valDays = '{$data.weekday}';
                        if (!valDays)
                            valDays = '1,2,3,4,5';
                        for (var i = 1; i <= 7; i++) {
                            document.write('<input type="checkbox" name="weekday[]" value="' + i + '"' + (valDays.indexOf(i) > -1 ? ' checked="checked"' : '') + '>星期' + days[i - 1]);
                        }
                    </script>
                </td></tr>
            <tr><th>临时休息日：</th><td>
                <textarea name="tempHolidays" cols="31" rows="12">{$data.tempHolidays}</textarea><br />
                <input type="text" name="date" class="easyui-datebox" value="" />
                <a href="#" class="addDate easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
                <a href="#" class="delDate easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
                </td></tr>
            <tr><th>临时工作日：</th><td>
                <textarea name="tempWorkDays" cols="31" rows="12">{$data.tempWorkDays}</textarea><br />
                <input type="text" name="date" class="easyui-datebox" value="" />
                <a href="#" class="addDate easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
                <a href="#" class="delDate easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
                </td></tr>
        </table>
        <input type="hidden" name="id" value="{$data.id}" />
    </form>
</block>
<block name="body_after_block">
    <script type="text/javascript">
        item_form.resize_owner_dialog({width:505});
        $('.addDate').click(function () {
            var $this = $(this);
            var $tr=$this.parentsUntil('tr').parent();
            var $ta = $tr.find('textarea');
            var $date=$tr.find('input[name="date"]');
            var val = $date.val();
            if (val == '') {
                alert('请填写一个日期!')
                return false;
            }
            var txt = $ta.val();
            if (txt.indexOf(val) > -1) {
                alert('此日期已添加过了!')
                return false;
            }
            txt = txt + val + '\n';
            $ta.val(txt);
            return false;
        });
        $('.delDate').click(function () {
            var $this = $(this);
            var $tr=$this.parentsUntil('tr').parent();
            var $ta = $tr.find('textarea');
            var $date=$tr.find('input[name="date"]');
            var val = $date.val();
            if (val == '') {
                alert('请填写一个日期！');
                return false;
            }
            var txt = $ta.val();
            var pattern = eval('/' + val + '\\n/g');
            txt = txt.replace(pattern, '');
            $ta.val(txt);
            return false;
        });
    </script>
</block>